package com.hz.zbl.service.impl;

import com.hz.zbl.mapper.UserMapper;
import com.hz.zbl.model.dto.TeacherDTO;
import com.hz.zbl.model.entity.UserEntity;
import com.hz.zbl.service.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {


    @Resource
    UserMapper userMapper2;

    @Override
    public List<TeacherDTO> allTeachers() {

        List<UserEntity> teacherEntities = userMapper2.selectAllTeacher();
        List<TeacherDTO> teachers = new ArrayList<>();
        teacherEntities.forEach(userEntity -> {
            TeacherDTO teacherDTO = new TeacherDTO(userEntity.getId(), userEntity.getUsername(), userEntity.getRealname(), userEntity.getTeacher_id());
            teachers.add(teacherDTO);
        });

        return teachers;
    }

    @Override
    public TeacherDTO getTeacherById(int teacher_id) {

        UserEntity teacher = userMapper2.selectTeacherById(teacher_id);
        if (teacher == null){
            return null;
        }
        TeacherDTO teacherDTO = new TeacherDTO(teacher.getId(), teacher.getUsername(), teacher.getRealname(), teacher_id);

        return teacherDTO;
    }
}
